package file;

import java.io.*;
import java.io.FileOutputStream;

public class write2 {
    public static void main(String[] agrs) {
        File file = new File("e:\\xx.txt");
        Student s1 = new Student("孙悟空", 23, "武侯区");
        Student s2 = new Student("孙悟空", 23, "武侯区");
        Student s3 = new Student("孙悟空", 23, "武侯区");
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
            oos.writeObject(s1);
            oos.writeObject(s2);
            oos.writeObject(s3);
            oos.close();
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
            while (true) {
                try {
                    Student s = (Student) ois.readObject();
                    System.out.println(s);
                } catch (EOFException e) {
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
